<template>
  <div class="warn-list">
    <div class="search-box">
      <div class="search-box-label">
        <span>商家</span>
        <el-input v-model="shop_name" placeholder="请输入商家名称"></el-input>
      </div>
      <div class="search-box-label">
        <span>关键字</span>
        <el-input v-model="keywords" placeholder="请输入条形码/商品"></el-input>
      </div>
      <div class="search-box-label">
        <span>生产日期</span>
        <el-date-picker
          v-model="production_date"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>
      <div class="search-box-label">
        <span>长保/短保</span>
        <el-select
          v-model="good_quality"
          class="radios"
          placeholder="请选择长保/短保"
        >
          <el-option label="长保" :value="1"> </el-option>
          <el-option label="短保" :value="2"> </el-option>
        </el-select>
      </div>
      <el-button type="primary" @click="search" class="search_btn">查询</el-button>
      <el-button @click="resetSearch">重置</el-button>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column label="编号" prop="warn_message_id"> </el-table-column>
      <el-table-column label="商家名称" prop="shop_name"> </el-table-column>
      <el-table-column label="条形码" prop="commo_code"> </el-table-column>
      <el-table-column label="商品名称" prop="commo_name"> </el-table-column>
      <el-table-column label="短保/长保" prop="good_quality">
        <template slot-scope="scope">
          {{ saveLong[scope.row.good_quality] }}
        </template>
      </el-table-column>
      <el-table-column label="保质期" prop="shelf_life"> </el-table-column>
      <el-table-column label="生产日期" prop="production_date">
      </el-table-column>
      <el-table-column label="到期日" prop="expiration_date" width="180px">
      </el-table-column>
      <el-table-column label="倒计时天数" prop="expire_day_mum">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="danger" size="small" @click="handleDelete(scope.row)"
            >核销</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="currentChange"
      :current-page="page"
      :page-size="size"
      layout="total, prev, pager, next"
      :total="total"
      background
    ></el-pagination>
  </div>
</template>

<script>
import * as api from "@/api/warnlist";
export default {
  name: "BatchList",
  data() {
    return {
      shop_name: "",
      keywords: "",
      production_date: "",
      good_quality:"",
      tableData: [],
      saveLong: {
        1: "长保",
        2: "短保",
      },
      page: 1,
      size: 10,
      total: 0,
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    getListData() {
      let data = {
        keywords: this.keywords,
        shop_name: this.shop_name,
        production_date: this.production_date,
        good_quality:this.good_quality,
        page: this.page,
        size: this.size,
      };
      api.getList(data).then((res) => {
        const { list, count } = res.data;
        this.tableData = list;
        this.total = count;
      });
    },
    search() {
      this.page = 1;
      this.getListData();
    },
    resetSearch() {
      this.shop_name = "";
      this.keywords = "";
      this.production_date = "";
      this.good_quality = "";
      this.page = 1;
      this.getListData();
    },
    handleDelete(row) {
      this.$confirm("确定要核销吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          api
            .checkoutBatchWarn({ warn_message_id_str: row.warn_message_id })
            .then((res) => {
              if (res.code == 200200) {
                this.$message.success(res.msg);
                this.getListData();
              }
            })
            .catch((err) => {
              this.$message.error(err.msg);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消核销",
          });
        });
    },
    currentChange(val) {
      this.page = val;
      this.getListData();
    },
  },
};
</script>

<style lang="scss" scoped>
.warn-list {
  padding: 40px;
  .search-box {
    display: flex;
    .el-button {
      height: 40px;
    }
    .el-input {
      width: 220px;
      margin-right: 15px;
    }

    .search-box-label {
      display: flex;
      align-items: center;
      box-sizing: border-box;
      font-size: 14px;
      margin-bottom: 20px;
      color: #333;
      span {
        // min-width: 50px;
        // text-align: right;
        margin-right: 10px;
        display: inline-block;
      }
      .filter-item {
        width: 200px;
      }
    }
    .search_btn{
      margin-left: 20px;
    }
  }
}
</style>
